using Engine;
using Game;

namespace RuthlessConquest {
    public class BusyDialog : Dialog {
        public LabelWidget m_largeLabelWidget;

        public LabelWidget m_smallLabelWidget;

        public string LargeMessage {
            get => m_largeLabelWidget.Text;
            set {
                m_largeLabelWidget.Text = value ?? string.Empty;
                m_largeLabelWidget.IsVisible = !string.IsNullOrEmpty(value);
            }
        }

        public string SmallMessage {
            get => m_smallLabelWidget.Text;
            set {
                m_smallLabelWidget.Text = value ?? string.Empty;
                m_smallLabelWidget.IsVisible = !string.IsNullOrEmpty(value);
            }
        }

        public BusyDialog(string largeMessage, string smallMessage) {
            Size = new Vector2(600, 240);
            ClampToBounds = true;
            HorizontalAlignment = WidgetAlignment.Center;
            VerticalAlignment = WidgetAlignment.Center;
            AddChildren(new RectangleWidget { FillColor = Color.Black, OutlineColor = new Color(128, 128, 128, 128), OutlineThickness = 2f });
            AddChildren(new InterlaceWidget());
            UniformSpacingPanelWidget container = new() {
                Direction = LayoutDirection.Vertical, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center
            };
            AddChildren(container);
            StackPanelWidget stackPanel = new() {
                Direction = LayoutDirection.Vertical, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center
            };
            container.AddChildren(stackPanel);
            m_largeLabelWidget = new LabelWidget {
                Name = "BusyDialog.LargeLabel",
                Color = Color.White,
                HorizontalAlignment = WidgetAlignment.Center,
                VerticalAlignment = WidgetAlignment.Near,
                Margin = new Vector2(10, 5)
            };
            stackPanel.AddChildren(m_largeLabelWidget);
            m_smallLabelWidget = new LabelWidget {
                Name = "BusyDialog.SmallLabel",
                Color = Color.Gray,
                HorizontalAlignment = WidgetAlignment.Center,
                VerticalAlignment = WidgetAlignment.Near,
                WordWrap = true,
                Margin = new Vector2(10, 5)
            };
            stackPanel.AddChildren(m_smallLabelWidget);
            container.AddChildren(
                new BusyBarWidget {
                    LitBarColor = Color.White,
                    UnlitBarColor = new Color(64, 64, 64, 64),
                    HorizontalAlignment = WidgetAlignment.Center,
                    VerticalAlignment = WidgetAlignment.Center
                }
            );
            LargeMessage = largeMessage;
            SmallMessage = smallMessage;
        }

        public override void Update() {
            if (Input.Back) {
                Input.Clear();
            }
        }
    }
}